package org.rescue.web;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

import org.rescue.search.*;


public class ManageConfiguration extends HttpServlet {

	public void doPost(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException {

		RequestDispatcher rd = null;
		
		if (request.getParameter("action") != null){
			String action = request.getParameter("action");

			//if (request.getParameter("dataset" != null)){
			//	int datasetId = Integer.valueOf(request.getParameter("dataset")).intValue();	
			//}
			
			
			if (action.equals("del")){
				//request.setAttribute("message", "action was: " + action + "id: " + datasetId + "was delete");	
				rd = getServletContext().getRequestDispatcher("/DeleteDataset.do");
			}
			else if (action.equals("save")) {
				rd = getServletContext().getRequestDispatcher("/SaveDataset.do");
			}
			else if (action.equals("open")) {
				rd = getServletContext().getRequestDispatcher("/OpenDataset.do");
			}
			else {
				// should never get here
				rd = request.getRequestDispatcher("manage_configuration.jsp");
			}
			rd.forward(request,response);
		}

		
		else {
			doGet(request,response);
		}
				
		

	}
	
	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException {


		DatasetDB datasetDB = new DatasetDB();	
		ArrayList<DatasetListing> listing = datasetDB.getDatasetListing(); 			
		request.setAttribute("listing", listing);	
		
		RequestDispatcher view = request.getRequestDispatcher("manage_configuration.jsp");
		view.forward(request,response);
				
		
	}
	
}
